package com.ironman.imes.device.event.listener;

import cn.hutool.core.util.StrUtil;
import com.ironman.imes.device.event.EventTopic;
import lombok.extern.slf4j.Slf4j;
import org.noear.dami.Dami;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DeviceEventAppStartedEventListener implements ApplicationListener<ApplicationStartedEvent> {
    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        log.info("DeviceEventAppStartedEventListener");
        Dami.<String, String>bus().listen(EventTopic.DEVICE_INFO_TOPIC, listener -> {
            String deviceCode = listener.getContent();
            if (StrUtil.isBlank(deviceCode)) {
                listener.reply(null);
            } else {
                // TODO 待实现HTTP 或 数据库
                listener.reply("TODO");
            }
        });
    }
}